<template>
	<view class="content">
		<view class="searchBox flex">
			<u-calendar :show="show" mode="range" @confirm="confirm" @close="show = false" :allowSameDay="true"
				:minDate="minDate" :closeOnClickOverlay="true" monthNum="13"></u-calendar>
			<view class="timeBox" @click="show = true">
				<span style="margin-right: 10rpx;">日期</span>
				<view class="time">
					<image src="../../static/img/time.png" mode=""></image>
					{{start_date}}
				</view>
				<view style="margin: 0 10rpx;">
					至
				</view>
				<view class="time">
					<image src="../../static/img/time.png" mode=""></image>
					{{end_date}}
				</view>
			</view>
			<view class="iptBox">
				<view class="searchBtn" @tap="getSchoolHourLog()">
					搜索
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list-box" v-for="(item,index) in list">
				<view class="school-data-box">
					<view class="school-data-left-box">
						<view class="school-data-title">收款人</view>
						<view class="school-data">{{item.collection_name}}</view>
					</view>
					<view class="school-data-right-box">
						<view class="school-data-title">收款账号</view>
						<view class="school-data">{{item.collection_account}}</view>
					</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-left-box">
						<view class="school-data-title">剩余小时</view>
						<view class="school-data">{{item.before_module_minute}}</view>
					</view>
					<view class="school-data-right-box">
						<view class="school-data-title">充值时间</view>
						<view class="school-data" style="color: #43CF7C;">{{item.create_time}}</view>
					</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-left-box">
						<view class="school-data-title">充值小时</view>
						<view class="school-data">{{item.module_minute}}</view>
					</view>
					<view class="school-data-right-box">
						<view class="school-data-title">充值后小时</view>
						<view class="school-data" style="color: #D43030;">{{item.after_module_minute}}</view>
					</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-title">录入人</view>
					<view class="school-data">{{item.admin.username}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				minDate: '',
				show: false,
				school_id: '',
				page: 1,
				size: 10,
				start_date: '',
				end_date: '',
				list: [],
			};
		},
		onLoad(option) {
			this.chooseTimed()
			this.school_id = option.school_id
			this.getData()
		},
		onReachBottom() {
			this.getData();
		},
		methods: {
			// 设置默认日期，最大值为今天，最小值为去年今天
			chooseTimed() {
				let date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (month <= 9) {
					month = '0' + month;
				}
				if (day <= 9) {
					day = '0' + day;
				}
				let minyear = year - 1;
				this.minDate = minyear + '-' + month + '-' + day;
				this.maxDate = year + '-' + month + '-' + day;
			},
			getDate() {
				const currentDate = new Date();
				const year = currentDate.getFullYear();
				const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份是从0开始的
				const day = currentDate.getDate().toString().padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;
				this.info.start_date = formattedDate
				this.info.end_date = formattedDate
			},
			confirm(e) {
				this.start_date = e[0].replace(/-/g, "-");
				this.end_date = e[e.length - 1].replace(/-/g, "-");
				this.show = false
			},
			async getData() {
				uni.stopPullDownRefresh();
				const {
					data: res
				} = await uni.$http.post('school/school/getSchoolHourLog', {
					school_id: this.school_id,
					page: this.page,
					size: this.size,
					start_date: this.start_date,
					end_date: this.end_date
				})
				if (res.code != 1) {
					return this.toast.msg(res.msg)
				}
				if (res.data.length) {
					this.list = this.list.concat(res.data);
					this.page += 1;
				} else {
					this.toast.msg('没有更多数据了！')
				}
			},
			getSchoolHourLog() {
				this.page = 1
				this.list = []
				this.getData();
			}
		}
	}
</script>

<style lang="scss">
	.list {
		width: 90%;
		margin-left: 5%;
		margin-top: 20rpx;
	}

	.list-box {
		width: 100%;
		height: 250rpx;
		border-radius: 5px;
		margin-bottom: 30rpx;
		padding: 20rpx 5%;
		border: 1px solid #E2E2E2;
	}

	.school-data-box {
		width: 100%;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 26rpx;
		font-weight: 400;
	}

	.school-data-title {
		width: 130rpx;
		height: 50rpx;
		color: #333333;
		float: left;
	}

	.school-data {
		height: 50rpx;
		color: #666666;
		float: left;
	}

	.school-data-left-box {
		width: 50%;
		height: 50rpx;
		float: left;
	}

	.school-data-right-box {
		width: 50%;
		height: 50rpx;
		float: left;
	}

	.content {
		.searchBox {
			width: 670rpx;
			margin: 0 auto;
			padding: 0 20rpx;

			.iptBox {
				width: 15%;
				display: flex;

				.ipt {
					box-sizing: border-box;
					width: 75%;
					height: 66rpx;
					padding-left: 75rpx;
					border: 2rpx solid #FCF7F7;
					border-radius: 10rpx;
				}

				.iptPla {
					height: 66rpx;
					line-height: 66rpx;
					color: #999;
					font-size: 22rpx;
				}

				.searchBtn {
					display: inline-block;
					background: #A6A6A6;
					width: 100%;
					height: 66rpx;
					line-height: 66rpx;
					text-align: center;
					border-radius: 10rpx;
					margin-left: 20rpx;
					font-size: 24rpx;
				}
			}
		}

		.timeBox {
			display: flex;
			height: 78rpx;
			line-height: 78rpx;
			align-items: center;
			font-size: 21rpx;
			width: 85%;

			.time {
				width: 40%;
				height: 78rpx;
				border-radius: 10rpx;
				background: #FFFFFF;
				border: 2rpx solid #FCF7F7;
				padding-left: 26rpx;
				color: #666;

				image {
					width: 35rpx;
					height: 35rpx;
					margin-right: 17rpx;
					vertical-align: middle;
				}
			}
		}
	}
</style>